#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1000005;
ll n,i,j,m,k,ans,a[N],T;
int main()
{
    std::ios::sync_with_stdio(false);
   freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    while(T--)
    {
        cin>>n;ans=0;
        for(i=1;i<=n;i++)cin>>a[i];
        for(i=2;i<=n;i++)
        {
            for(j=i-1;j>=1;j--)
            {
                if(a[i]==a[j])
                {
                    ans+=a[i];break;
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}
